package ru.evga.inse.server.gwt.common.client.filter.dict;

import ru.evga.inse.server.gwt.common.client.filter.FilterPanel;
import ru.evga.inse.server.gwt.common.client.filter.IFilterListener;

import com.google.gwt.user.client.ui.TextBox;


public class CityFilterPanel
    extends FilterPanel
{
    private TextBox name;
    private IFilterListener<CityFilterObject> filterListener;

    public CityFilterPanel(IFilterListener<CityFilterObject> filterListener)
    {
        this.filterListener = filterListener;
        name = new TextBox();
        init(name);
    }

    private  CityFilterObject getFilterObject()
    {
        CityFilterObject cityFilterObject = CityFilterObject.createEmptyCityFilter();
        cityFilterObject.setName(name.getText());
        return cityFilterObject;
    }

    @Override
    protected void applyFilter()
    {
        if(filterListener != null)
        {
            filterListener.applyFilter(getFilterObject());
        }
    }

    @Override
    protected void clearFilter()
    {
        name.setText("%");
        applyFilter();
    }
}
